import unittest
from symbol import parameters


def add(x,y):
    # 待测方法
    return x+y
class TestIhrmLogin(unittest.TestCase):
    def test01_add(self):
        result = add(10,20)
        self.assertEqual(30,result)

    def test02_add(self):
        result = add(100,200)
        self.assertEqual(30,result)

    def test03_add(self):
        result = add(1000,20)
        self.assertEqual(1020,result)


def add(x,y):
    return x + y
data = [{"x":"10","y":"20","except":30},
        {"x":"100","y":"200","except":300},
        {"x":"1000","y":"20","except":1020},
        {"x":"4","y":"18","except":23}
]

def read_json_data():
    list_data = []
    for item  in data:
        tmp = tuple(item.values())
        list_data.append(tmp)

class TeatAdd(unittest.TestCase):
    #通用测试方法实现参数化
    @parameters.expand(read_json_data())
    def test_add(self,x,y,except_data):
        result = add(x,y)
        self.assertEqual(result,except_data)

